﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.App_Code;
using QXBook.Model;
using QXBook.Utils;
using QXBook.Service;
using QXBook.Controls.HtmlControls;

namespace Web.Video
{
    public partial class Video_List : UserBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                VideoCondition condition = new VideoCondition();

                if (!string.IsNullOrEmpty(CommonUtils.Get("CategoryID")))
                {
                    condition.CategoryID = CommonUtils.ToInt(CommonUtils.Get("CategoryID"));
                }

                this.TextBind(condition);
            }
        }

        private void TextBind(VideoCondition condition)
        {
            PagerState ps = new PagerState();
            if (string.IsNullOrEmpty(CommonUtils.Get("page")))
            {
                ps.CurrentPage = 1;
            }
            else
            {
                ps.CurrentPage = CommonUtils.ToInt(CommonUtils.Get("page"));
            }
            ps.PageSize = 20;

            List<VideoInfo> list = ServiceFactory.CreateInstance<VideoService>().GetModelList(ref ps, condition);

            this.rptList.DataSource = list;
            this.rptList.DataBind();

            //divPage.InnerHtml = ClientPager.CreatePager(ps);
        }

        protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            VideoInfo video = (VideoInfo)e.Item.DataItem;
            Label lblAddDate = (Label)e.Item.FindControl("lblAddDate");
            PlaceHolder phImg = (PlaceHolder)e.Item.FindControl("phImg");
            Anchor aTitle = (Anchor)e.Item.FindControl("aTitle");

            lblAddDate.Text = video.AddDate.ToString("yyyy-MM-dd");
            if (!string.IsNullOrEmpty(video.SmallImg))
            {
                phImg.Visible = true;
            }
            else
            {
                phImg.Visible = false;
            }
        }
    }
}